package com.gms.config;

import com.gms.interceptor.CheckUserInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class MyMVCConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){

        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/").addResourceLocations("file:c:/ProgramData/file/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> list = new ArrayList<>();
        list.add("/**/*.css");
        list.add("/**/*.js");
        list.add("/**/*.png");
        list.add("/css/**");
        list.add("/images/*");
        list.add("/js/*");
        list.add("/loginUser");
        list.add("/login");
        list.add("/toregister");
        list.add("/register");
        list.add("/registerUser");
        list.add("/defaultKaptcha");
        registry.addInterceptor(new CheckUserInterceptor()).addPathPatterns("/**").excludePathPatterns(list);
    }
}
